﻿using System.Linq;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

namespace RestoArenaHelper
{
    internal static class Spell
    {
        public static bool Cast(string spell, WoWUnit onUnit)
        {
            if (onUnit != null)
                if (SpellManager.CanCast(spell, onUnit))
                    return SpellManager.Cast(spell, onUnit);
            return false;
        }

        public static bool HasMyAura(string aura, WoWUnit u)
        {
            return u.GetAllAuras().Any(a => a.Name == aura && a.CreatorGuid == StyxWoW.Me.Guid);
        }

        public static bool HasMyAura(this WoWUnit unit, string aura)
        {
            return unit.GetAllAuras().Any(a => a.Name == aura && a.CreatorGuid == StyxWoW.Me.Guid);
        }

        public static double GetAuraTimeLeft(string aura, WoWUnit onUnit)
        {
            if (onUnit != null)
            {
                var result = onUnit.GetAuraByName(aura);
                if (result != null)
                {
                    if (result.TimeLeft.TotalSeconds > 0)
                        return result.TimeLeft.TotalSeconds;
                }
            }
            return 0;
        }

        public static uint LifebloomStackCount(WoWUnit unit)
        {
            {
                if (unit != null)
                {
                    WoWAura result = unit.GetAllAuras().FirstOrDefault(a => a.Name == "Lifebloom" && a.StackCount > 0);
                    if (result != null) return result.StackCount;
                }
                return 0;
            }
        }
    }
}